//# sourceURL=http://uMapApp/Module/Bridge/BridgeDetectionNodeBlock
define([
    "mhjs/mhjs"
    , "../../UI/Panel/PanelBlock/PanelBlock"
], function (
    mhjs,
    PanelBlock
) {

    function BridgeDetectionNodeBlock(option) {

        var _this = this;
        _this.isOpened = false;

        PanelBlock.call(_this, option);
        _this.addClass("BridgeDetectionNodeBlock propertiesBlock");

        _this.append(_this.renderButton());

    }

    var _class = BridgeDetectionNodeBlock;
    mhjs.Inherit(_class, PanelBlock);


    Object.defineProperties(_class.prototype, {
        "properties"  : {
            set: function (properties) {
                var _this = this;
                _this._properties = properties;

                _this.ui.wrap.empty();

                _this.title = properties.title;

                _this.ui.wrap
                    .append(_this.renderStatus("报警状态", _this.properties.status))
                    .append(_this.renderStatus("设备状态", _this.properties.equipmentStatus || {
                        "label": "正常", "className": "normal"
                    }))
                    .append(_this.renderItem("最新数值", _this.properties.lastData && _this.properties.lastData.value || 0.0))
                    .append(_this.renderItem("更新时间", _this.properties.lastData && _this.properties.lastData.time || new Date().format("yyyy-MM-dd hh:mm:ss")))
                    .append(_this.renderItem("报警上限", 15))
                    .append(_this.renderItem("报警下限", -15))
                    .append(_this.renderItem("位置", _this.properties["名称"]))
                ;


            },
            get: function () {
                return this._properties;
            }
        },
        "renderButton": {
            value: function () {
                var _this = this;

                var button = new mhjs.Div({"class": "button"});
                button.text("详细数据");

                button.on("click", function () {
                    _this.properties.trigger("propertiesButtonClick");
                });

                return button;

            }
        },
        "renderStatus": {
            value: function (label, status) {
                var _this = this;

                var item = _this.renderItem(label, status.label);
                item.valuetext.addClass("status");
                item.valuetext.addClass(status.className);

                return item;

            }
        },
        "renderTree"  : {
            value: function (label, value) {

                var _this = this;
                var result;

                if (typeof value !== "object" || value === undefined) {
                    result = _this.renderItem(label, value);
                } else {
                    result = _this.renderFolder(label);

                    $.each(value, function (childLabel, childValue) {
                        result.child.append(_this.renderTree(childLabel, childValue));
                    });
                }

                return result;

            }
        },
        "renderFolder": {
            value: function (label) {

                var folder = new mhjs.Div({"class": "folder"});
                folder.label = new mhjs.Div({"class": "label"});
                folder.label.text(label);
                folder.child = new mhjs.Div({"class": "child"});

                folder
                    .append(folder.label)
                    .append(folder.child)
                ;
                return folder;
            }
        },
        "renderItem"  : {
            value: function (label, value) {

                var item = new mhjs.Div({"class": "item"});
                item.label = new mhjs.Div({"class": "label"});
                item.label.text(label);
                item.valuetext = new mhjs.Div({"class": "value"});
                item.valuetext.text(value);

                item
                    .append(item.label)
                    .append(item.valuetext)
                ;
                return item;
            }
        },
        "map"         : {
            set: function (map) {
                var _this = this;
                _this._map = new mhjs.Map(map);
            },
            get: function () {
                return this._map;
            }
        }
    });

    return _class;

});